<?php
namespace app\model;

use think\Model;

class Factory extends Model
{
    const IS_DELETE_NO = 0; //没删除
    
    /**
     * 判断名称是否存在
     * @author 吴伟亮
     * @param string $name
     * @return void
     */
    public function checkNameIsExist(string $name)
    {
        $info = $this->field('id')
            ->where('name', $name)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return null;
        }

        return $info['id'];
    }

    /**
     * 判断key是否存在
     * @author 吴伟亮
     * @param string $key
     * @return void
     */
    public function checkKeyIsExist(string $key)
    {
        $info = $this->field('id')
            ->where('key', $key)
            ->where('delete_time', self::IS_DELETE_NO)
            ->find();
        if (!$info) {
            return null;
        }

        return $info['id'];
    }
}